#include "svgwindow.h"
#include <QMouseEvent>
#include <QScrollBar>
SvgWindow::SvgWindow()
{
    svgWidget =new SvgWidget;
    setWidget(svgWidget);
}

void SvgWindow::setFile(QString fileName)
{
    svgWidget->load(fileName); //(a)
    QSvgRenderer *render =svgWidget->renderer();
    svgWidget->resize(render->defaultSize()); // (b)
}

void SvgWindow::mousePressEvent(QMouseEvent *event)
{
    mousePressPos =event->pos();
    scrollBarValuesOnMousePress.rx() = horizontalScrollBar()->value();
    scrollBarValuesOnMousePress.ry() = verticalScrollBar()->value () ;
    event->accept();
}

void SvgWindow::mouseMoveEvent(QMouseEvent *event)
{
    horizontalScrollBar()->setValue(scrollBarValuesOnMousePress.x()-event->pos() .x()+mousePressPos.x()); //对水平滚动条的新位置进行设置
    verticalScrollBar()->setValue(scrollBarValuesOnMousePress.y()- event->pos() .y()+mousePressPos.y()); //对垂直滚动条的新位置进行设置
    horizontalScrollBar()->update();
    verticalScrollBar()->update();
    event->accept();
}
